package gui.admin.tablemodel;

import dao.PurchaseDao;
import dao.SaleDao;
import entity.Purchase;
import entity.Sale;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.util.List;

public class PurchaseTableModel extends DefaultTableModel {
    PurchaseDao purchaseDao = new PurchaseDao();
    String[] tableHeaders = new String[]{"供货单编号","供货商编号","经手人姓名","供货单总金额","供货单日期"};//供货单信息表头
    List purchaseList = null;
    String[][] purchaseData = null;
    public PurchaseTableModel() throws Exception {
        purchaseList = purchaseDao.getAllpurchase();
        purchaseData = new String[purchaseList.size()][tableHeaders.length];
        for (int i = 0; i < purchaseList.size(); i++) {
            Purchase purchase = (Purchase)purchaseList.get(i);
            purchaseData[i][0] = purchase.getPurchaseId();//设置表格第i行第1列
            purchaseData[i][1] = purchase.getSupplierId();
            purchaseData[i][2] = purchase.getHandlerName();
            purchaseData[i][3] = String.valueOf(purchase.getPurchaseTotalPrice());
            purchaseData[i][4] = purchase.getPurchaseDate();
        }
        this.setDataVector(purchaseData,tableHeaders);
    }

}
